package com.yoyo.web.action;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;

import com.yoyo.biz.WeiboInfoBiz;
import com.yoyo.entity.WeiboInfo;

@Controller
public class TsetWeiboInfo {
	
	@Resource
	private WeiboInfoBiz weibobiz;
	private List<WeiboInfo> weibos;
	private WeiboInfo weibo;
	private String json;
	
	public WeiboInfoBiz getWeibobiz() {
		return weibobiz;
	}
	public void setWeibobiz(WeiboInfoBiz weibobiz) {
		this.weibobiz = weibobiz;
	}
	public List<WeiboInfo> getWeibos() {
		return weibos;
	}
	public void setWeibos(List<WeiboInfo> weibos) {
		this.weibos = weibos;
	}
	public WeiboInfo getWeibo() {
		return weibo;
	}
	public void setWeibo(WeiboInfo weibo) {
		this.weibo = weibo;
	}
	public String getJson() {
		return json;
	}
	public void setJson(String json) {
		this.json = json;
	}
	
//	public String getIndexWeibo(){
//		weibos = weibobiz.findOrder("desc", 0, 4);
//		return "json";
//	}
	
	public String getItem(){
		JSONObject jsonObj = JSONObject.fromObject(json);
		weibo=weibobiz.find(2);
		weibo.setWeiboText(jsonObj.get("weiboText").toString());
		weibobiz.save(weibo);
		return "json";
	}
	
	public String saveWeibo(){
		//Map seesion = (Map)ActionContext.getContext().getSession().get("user");
		JSONObject jsonObj = JSONObject.fromObject(json);
		//weibo.setUid((Integer)seesion.get("id"));
		weibo.setWeiboText(jsonObj.get("weiboText").toString());
		weibo.setTime(new Date());
		weibobiz.save(weibo);
		return "json";
	}

}
